<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 
 <!DOCTYPE html>
<html>

<head>
	<base href="/">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>用户</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="static/templet/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="static/templet/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="static/templet/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="static/templet/css/animate.min.css" rel="stylesheet">
    <link href="static/templet/css/style.min862f.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
    	<form method="post" id="keyWordForm" action = "keyWordG/proxy/list">
        <div class="row">    
        <!-- 检索 -->
        	<div class="col-sm-12">
        		<table class="table table-hover">
        			<tr>
        				<td >
        					<div class="input-group">
							     <input type="text" class="form-control" onkeydown="onKeyDown(event)" name="domain" id="domain" value="${pam.domain}" placeholder="请输入域名"/>
							</div>
        				</td>
        				<td >
        					<select class="form-control" name="typeValue" id="typeValue" data-placeholder="搜索引擎" style="vertical-align:top;width:150px;">
					            <option value="">搜索引擎</option>
					            <c:forEach items="${engineList}" var="engin">
					            	<option value="${engin.code }" <c:if test="${pam.typeValue == engin.code}">selected</c:if>>${engin.name  }</option>
					            </c:forEach>
					        </select>
        				</td>
        				<td >
        					<select class="form-control" name="state" id="state" data-placeholder="关键字状态" style="vertical-align:top;width: 150px;">
					            <option value="">关键字状态</option>
					            <option value="01" <c:if test="${pam.state == '01'}">selected</c:if>>使用中</option>
					            <option value="02" <c:if test="${pam.state == '02'}">selected</c:if>>已停用</option>
					        </select>
        				</td>
        				<td >
        					<select class="form-control" name="orderBy" id="orderBy" data-placeholder="排序方式" style="vertical-align:top;width: 150px;">
					            <option value="">排序方式</option>
					            <option value="createTime" <c:if test="${pam.orderBy == 'createTime'}">selected</c:if>>添加日期</option>
					            <option value="comDay" <c:if test="${pam.orderBy == 'comDay'}">selected</c:if>>达标天数</option>
					            <option value="newRanking" <c:if test="${pam.orderBy == 'newRanking'}">selected</c:if>>最新排名</option>
					            <option value="price" <c:if test="${pam.orderBy == 'price'}">selected</c:if>>价格</option>
					        </select>
        				</td>
        				<td >
        					<select class="form-control" name="isTarget" id="isTarget" data-placeholder="达标情况" style="vertical-align:top;width: 150px;">
					            <option value="">达标情况</option>
					            <option value="00" <c:if test="${pam.isTarget == '00'}">selected</c:if>>未达标</option>
					            <option value="01" <c:if test="${pam.isTarget == '01'}">selected</c:if>>已达标</option>
					        </select>
        				</td>
        				<td >
        					<select class="form-control" name="userState" id="userState" data-placeholder="用户状态" style="vertical-align:top;width: 150px;">
					            <option value="">用户状态</option>
					            <option value="01" <c:if test="${pam.userState == '01'}">selected</c:if>>正常</option>
					            <option value="02" <c:if test="${pam.userState == '02'}">selected</c:if>>禁用</option>
					        </select>
        				</td>
        				<td >
        					<select class="form-control" name="serviceState" id="serviceState" data-placeholder="服务状态" style="vertical-align:top;width: 150px;">
					            <option value="">服务状态</option>
					            <option value="00" <c:if test="${pam.serviceState == '00'}">selected</c:if>>服务中</option>
					            <option value="01" <c:if test="${pam.serviceState == '01'}">selected</c:if>>停止服务</option>
					        </select>
        				</td> 
        				<td >
        					<div class="input-group">
							     <input type="text" class="form-control" onkeydown="onKeyDown(event)" name="userName" id="userName" value="${pam.userName}" placeholder="请输入用户名"/>
							</div>
        				</td>
        				<td >
        					<div class="input-group">
							     <input type="text" class="form-control" onkeydown="onKeyDown(event)" name="keyWord" id="keyWord" value="${pam.keyWord}" placeholder="请输入关键字"/>
							</div>
        				</td>
        				<td style="width:1%;">
        					<span style="float:right;"><input type="button" class="btn btn-primary" onclick="searchs();" value="检索"/></span>
        				</td>
        			</tr>
        		</table>
			</div>      
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <table class="table table-hover" id="keyWordTable">
                            <thead>
                                <tr>
                                    <th class="text-center">id</th>
                                    <th class="text-center">用户名</th>
                                    <th class="text-center">关键词</th>
                                    <th class="text-center">类型</th>
                                    <th class="text-center">域名</th>
                                    <th class="text-center">指数</th>
                                    <th class="text-center">单价</th>
                                    <th class="text-center">目标排名</th>
                                    <th class="text-center">扣费详情</th>
                                    <th class="text-center">状态</th>
                                    <th class="text-center">更新日期</th>
                                    <th class="text-center">使用天数</th>
                                    <th class="text-center">达标天数</th>
                                    <th class="text-center">初始排名</th>
                                    <th class="text-center">昨日排名</th>
                                    <th class="text-center">最新排名</th>
                                    <th class="text-center">达标状态</th>
                                    <th class="text-center">用户欠费状态</th>
                                    <th class="text-center">操作</th>
                                </tr>
                            </thead>
                            <tbody>
							<c:forEach items="${page.list}" var="key" varStatus="vs">
                            	<tr class="text-center">
                                    <td>${key.id }</td>
									<td>${key.userName }</td>
									<td><a href="${key.engineUrl }${key.keyWordName }" target="_blank" title="详情">${key.keyWordName }</a></td>
									<td>${key.typeValue }</td>
									<td>${key.domain }</td>
									<td>
										<c:choose>
											<c:when test="${key.keywordIndex == '-1'}">
												0
											</c:when>
											<c:otherwise>
												${key.keywordIndex }
											</c:otherwise>
										</c:choose>
									</td>
									<td>${key.price }</td>
									<td>${key.targetRanking }</td>
									<td> <a  href="javascript:billingDetails('${key.keyWordName }','${key.engine_code }','${key.domain }');" title="详情">详情</a></td>
									<td>
										<c:if test="${key.state == '00'}">
											待审核
										</c:if>
										<c:if test="${key.state == '01'}">
											使用中
										</c:if>
										<c:if test="${key.state == '02'}">
											已停用
										</c:if>
										<c:if test="${key.state == '03'}">
											禁用
										</c:if>
									</td> 
									<td>
										<fmt:parseDate value="${key.updateTime }" pattern="yyyy-MM-dd" var="utime"/> 
										<fmt:formatDate value="${utime}" pattern="yyyy-MM-dd"/>
									</td>
									<td>${key.useDay }</td>
									<td>${key.reachDays }</td>
									<td>
										<c:choose>
											<c:when test="${key.initRanking == '-1'}">
												-
											</c:when>
											<c:when test="${key.initRanking == '10000'}">
												100+
											</c:when>
											<c:otherwise>
												${key.initRanking }
											</c:otherwise>
										</c:choose>
									</td>
									<td>
										<c:choose>
											<c:when test="${key.ydayRanking == '-1'}">
												-
											</c:when>
											<c:when test="${key.ydayRanking == '10000'}">
												100+
											</c:when>
											<c:otherwise>
												${key.ydayRanking }
											</c:otherwise>
										</c:choose>
									</td>
									<td>
										<c:choose>
											<c:when test="${key.newRanking == '-1'}">
												-
											</c:when>
											<c:when test="${key.newRanking == '10000'}">
												100+
											</c:when>
											<c:otherwise>
												${key.newRanking }
											</c:otherwise>
										</c:choose>
									</td>
									<td>
										<c:if test="${key.isTarget == '00'}">
											未达标
										</c:if>
										<c:if test="${key.isTarget == '01'}">
											已达标
										</c:if>
									</td>
									<td>
										<c:if test="${key.serviceState == '00'}">
											服务中
										</c:if>
										<c:if test="${key.serviceState == '01'}">
											已停用
										</c:if>
									</td>	
									<td>
											<a  href="javascript:editprice('${key.id }','${key.price }','${key.targetRanking }');" title="修改">修改</a>
										<c:if test="${key.state == '01'}">
                                    		<a  href="javascript:keyWordReview('${key.keywordsId }','${key.state }','02');" title="停用">停用</a>
	                                    </c:if>
	                                    <c:if test="${key.state == '02'}">
	                                    	<a  href="javascript:keyWordReview('${key.keywordsId }','${key.state }','01');" title="使用">使用</a>
	                                    </c:if>
									</td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                        <jsp:include page="/WEB-INF/jsp/page.jsp">
                        	<jsp:param value="keyWordForm" name="form"/>
                        </jsp:include>
                    </div>
                </div>
            </div>
        </div>
        </form>
    </div>
    <script src="static/templet/js/jquery.min.js?v=2.1.4"></script>
    <script src="static/templet/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="static/templet/js/plugins/peity/jquery.peity.min.js"></script>
    <script src="static/templet/js/plugins/layer/layer.min.js"></script>
    <script src="static/templet/js/iframe.min.js"></script>
    <script src="static/templet/js/plugins/layer/laydate/laydate.js"></script>
    <script type="text/javascript">
    
    function billingDetails(name,typeValue,domain){
    	parent.layer.open({
    	    type: 2,
    	    title: '账单',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['80%', '70%'],
    	    content: 'bill/keyWordDeduc?keyWord='+ name + '&engine_code=' + typeValue + '&domain=' +domain,
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }
    
    function searchs(){
    	$("#keyWordForm").attr("action","keyWordG/proxy/list")
    	$("#keyWordForm").submit();
    }
    
  //修改排名和价格
	function editprice(ids,price,targetRanking){
    	parent.layer.open({
    	    type: 2,
    	    title: '关键字',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['40%', '30%'],
    	    content: 'keyWordG/editPricePage?ids='+ids + '&price=' + price + '&targetRanking=' + targetRanking,
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }
  
	//修改
	function keyWordReview(ids,oldState,newState){
		if(ids == null){
			alter("数据有误");
			return false;
		}
		var msg = "";
		if(newState == "01"){
			msg = "是否启用";
		}else if(newState == "02"){
			msg = "是否停用";
		}
		layer.confirm(msg,function(index){
			$.ajax({
				type: 'get',
				url: 'keyWordG/keyWordEnable',
				data: {ids : ids,oldState : oldState,newState : newState},
				success: function(data){
					layer.msg('成功!',{icon: 1,time:2000});
					setTimeout(function(){
						window.location.reload();
					},1000)
				},
				error:function(data) {
					console.log(data.msg);
				},
			});	
		});	
	}
    </script>

</body>

</html>